package com.stone.framework.task.schedule;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.stone.framework.task.client.AbstractClient;
import com.stone.framework.task.client.ClientFactory;
import com.stone.framework.task.entity.ScheduleConfig;

public class ScheduleJob extends QuartzJobBean {

    public static final String JOB_PARAM_KEY = "JOB_PARAM_KEY";

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        ScheduleConfig config = (ScheduleConfig)context.getMergedJobDataMap().get(JOB_PARAM_KEY);

        String serviceName = config.getServiceName();
        String jobName = config.getJobName();
        String params = config.getParams();

        AbstractClient client = ClientFactory.valueOf(serviceName).getBean();
        client.start(jobName, params);
    }

}
